package com.bruce.starts.demo.commonerror.jdk8;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class CollectorDemo {
    private List<People> peopleList;

    public void setPeopleList(List<People> peopleList) {
        this.peopleList = peopleList;
    }

    public List<People> getPeopleList() {
        return peopleList;
    }

    public static void main(String[] args) {
        People p1 = new People("bruce","江西");
        People p2 = new People("bruce","江西");
        People p3 = new People("bruce1","江西2");
        CollectorDemo collectorDemo = new CollectorDemo();
        collectorDemo.setPeopleList(Stream.of(p1,p2,p3).collect(Collectors.toList()));
        collectorDemo.getPeopleList().stream().collect(
                Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<>(Comparator.comparing(people->people.getName()+people.getAddress()))),ArrayList::new
                        )
        );
        collectorDemo.getPeopleList().forEach(p-> System.out.println(p.getName()+":"+p.getAddress()));
    }
}
class People{
    String name;
    String address;

    public People(String name, String address) {
        this.name = name;
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}
